package com.eliza.music.model.vm

import androidx.lifecycle.ViewModel
import com.eliza.library.utils.net.HttpClient
import com.eliza.library.utils.net.RespResult
import io.ktor.http.URLBuilder
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import javax.inject.Inject


data class LoginReq(var username: String, var password: String) {

}

enum class UserAction {
    Login,
    Register
}


data class LoginState(
    var auth: Boolean,
)


class LoginVM @Inject constructor() : ViewModel() {
    private var _loginState = MutableStateFlow(LoginReq("", ""))
    val loginState: StateFlow<LoginReq> = _loginState.asStateFlow()

    val authSuccess = false

    val httpClient = HttpClient(URLBuilder("http://localhost:8081"))
    fun Update(username: String, password: String) {
        _loginState.value.username = username
        _loginState.value.password = password
    }

    suspend fun tryLogin() {
        httpClient.postx<RespResult<Any>>("/login") {}
    }
}
